
//middle
<div class="container" id="middle">
<form action="#" method="post">
<div id="Oobj15"><input type="text" id="Gform15" class="dfltf" name="company" value="Company">
</div><div id="Oobj14"><input type="text" id="Gform14" class="dfltf" name="web" value="Web Address">
</div><div id="Oobj4"><input type="text" id="Gform4" class="dfltf" name="first" value="First Name">
</div><div id="Oobj5"><input type="text" id="Gform5" class="dfltf" name="last" value="Last Name">
</div><div id="Oobj6"><input type="text" id="Gform6" class="dfltf" name="address" value="Address">
</div><div id="Oobj7"><input type="text" id="Gform7" class="dfltf" name="city" value="City">
</div><div id="Oobj8"><input type="text" id="Gform8" class="dfltf" name="state" value="State">
</div><div id="Oobj9"><input type="text" id="Gform9" class="dfltf" name="zip" value="Zip code">
</div><div id="Oobj10"><input type="text" id="Gform10" class="dfltf" name="officenum" value="Office Number">
</div><div id="Oobj11"><input type="text" id="Gform11" class="dfltf" name="tollfree" value="Toll free Number">
</div><div id="Oobj12"><input type="text" id="Gform12" class="dfltf" name="fax" value="Fax">
</div><div id="Oobj13"><input type="text" id="Gform13" class="dfltf" name="email" value="Email">
</div>
<div id="Oobj30"><select class="dfltf" name='service[]' size="13" multiple="multiple">
<option value="airtrans" <?php isServiceSelected('airtrans'); ?>> Airport Service</option>
<option value="wedding" <?php isServiceSelected('wedding'); ?>> Weddings</option>
<option value="prom" <?php isServiceSelected('prom'); ?>> Prom</option>
<option value="bachelor" <?php isServiceSelected('bachelor'); ?>> Bachelor(ette) Party</option>
<option value="anniversaries" <?php isServiceSelected('anniversaries'); ?>> Anniversaries</option>
<option value="pt2pt" <?php isServiceSelected('pt2pt'); ?>> Point 2 Point</option>
<option value="birthday" <?php isServiceSelected('birthday'); ?>> Birthday Parties</option>
<option value="concert" <?php isServiceSelected('concert'); ?>> Concerts</option>
<option value="grads" <?php isServiceSelected('grads'); ?>> Graduation</option>
<option value="sports" <?php isServiceSelected('sports'); ?>> Sports Events</option>
<option value="holiday" <?php isServiceSelected('holiday'); ?>> Holiday Light Tours</option>
<option value="nightout"<?php isServiceSelected('nightout'); ?>> Night on the Town</option>
<option value="other" <?php isServiceSelected('other'); ?>> Other</option>
</select>
</div>

><div id="Oobj32"><select class="dfltf" name="fleet[]" size="12" multiple="multiple">
<option value="sedan" <?php isFleetSelected('sedan'); ?>> Sedan</option>
<option value="limo" <?php isFleetSelected('limo'); ?>> Limosuine</option>
<option value="stretchlimo" <?php isFleetSelected('stretchlimo'); ?>> Stretch Limo</option>
<option value="van" <?php isFleetSelected('van'); ?>> Van</option>
<option value="paratrans" <?php isFleetSelected('paratrans'); ?>> Paratransit Van</option>
<option value="handicap" <?php isFleetSelected('handicap'); ?>> Handicap Access</option>
<option value="suv" <?php isFleetSelected('suv'); ?>> S.U.V.</option>
<option value="minibus" <?php isFleetSelected('minibus'); ?>> Mini bus</option>
<option value="antique" <?php isFleetSelected('antique'); ?>> Antique Vehicles</option>
<option value="rolls" <?php isFleetSelected('rolls'); ?>> Rolls Royce</option>
<option value="bus620" <?php isFleetSelected('bus620'); ?>> Party Bus 6-20</option>
<option value="bus20up" <?php isFleetSelected('bus20up'); ?>> Party Bus 20+</option>
</select></div>

<div id="Oobj29"><input type="text" id="Gform26" class="dfltf" name="airport1" value="1st airport">
</div><div id="Oobj27"><input type="text" id="Gform24" class="dfltf" name="airport5" value="5th airport">
</div><div id="Oobj22"><input type="text" id="Gform19" class="dfltf" name="airport2" value="2nd airport">
</div><div id="Oobj26"><input type="text" id="Gform23" class="dfltf" name="airport6" value="6th airport">
</div><div id="Oobj28"><input type="text" id="Gform25" class="dfltf" name="airport3" value="3rd airport">
</div><div id="Oobj24"><input type="text" id="Gform21" class="dfltf" name="airport7" value="7th airport">
</div><div id="Oobj23"><input type="text" id="Gform20" class="dfltf" name="airport4" value="4th airport">
</div><div id="Oobj25"><input type="text" id="Gform22" class="dfltf" name="airport8" value="8th airport">
</div><div id="Oobj34"><input type="text" id="Gform30" class="dfltf" name="targetzip1" value="Target Zipcode">
</div><div id="Oobj45"><input type="text" id="Gform36" class="dfltf" name="targetzip2" value="Target Zipcode">
</div><div id="Oobj44"><input type="text" id="Gform34" class="dfltf" name="targetzip3" value="Target Zipcode">
</div><div id="Oobj46"><input type="text" id="Gform37" class="dfltf" name="targetzip4" value="Target Zipcode">
</div><div id="Oobj43"><input type="submit" class="dfltf" name="submit" value="Submit">
</div></form>

<div id="Oobj37">
<div id="Grtf76" class="dfltt">
<span class ="txt0"><span class ="bold">What is your target area?</span><br>
</span></div>
</div>

<div id="Oobj31">
<div id="Grtf57" class="dfltt">
<span class ="txt0"><span class ="bold">Your services</span></span><span class ="txt1"> (select all that apply)<br>
</span></div>
</div>

<div id="Oobj33">
<div id="Grtf70" class="dfltt">
<span class ="txt0"><span class ="bold">FLEET </span></span><span class ="txt1">(select all that apply)<br>
</span></div>
</div>

</div>



   </div></div>  
   



</div>
<?php
echom('start');
@$service=$_POST['service'];

if(is_array($service))
{
	while (list ($key, $val) = each($service))
	{
		echom("key: $key <br>val: $val <br>");
	}
}
else{echom($service);}
echom($service);
/*
$service=$_POST['service'];
if ($service)
{
    echo date(); 
    foreach($service as $srv)
        echo $srv;
}*/
?>
<?php
function isServiceSelected($option)
{
	//echo '<br> iss - ' . $option . '<br>';
	@$service=$_POST['service'];
	if(is_array($service))
	{
		while (list ($key, $val) = each($service))
		{
			if ($val == $option) echo 'selected';
		}
	}	
}

function isServiceSelectedYN($option)
{
	//echo '<br> iss - ' . $option . '<br>';
	@$service=$_POST['service'];
	if(is_array($service))
	{
		$retval = 'N';
		while (list ($key, $val) = each($service))
		{
			if ($val == $option) $retval = 'Y';
			//echom('<br>$val' . $val . ' $option' . $option . ' $retval ' . $retval . '<br>');
		}		
	}
	//echom("<h2>$retval</h2>");
	return $retval;
} 
function isFleetSelectedYN($option)
{
	//echo '<br> iss - ' . $option . '<br>';
	@$service=$_POST['fleet'];
	if(is_array($service))
	{
		$retval = 'N';
		while (list ($key, $val) = each($service))
		{
			if ($val == $option) $retval = 'Y';
			//echom('<br>$val' . $val . ' $option' . $option . ' $retval ' . $retval . '<br>');
		}		
	}
	//echom("<h2>$retval</h2>");
	return $retval;
} 
function isFleetSelected($option)
{
	@$fleet=$_POST['fleet'];	
	if(is_array($fleet))
	{
		while (list ($key, $val) = each($fleet))
		{
			if ($val == $option) echo 'selected';
		}
	}	
}
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
try {
//test
echom('<br> is array:' . is_array($_POST['service']) . ' - count: ' . count($_POST['service']) . '<br>');
$id = 1;
$c = $_POST['service'];
echom('<br>' . $c[0] . ' --- ' . $c[1] . '<br>');

//endtest
	echom('<br> postback');
	$company = isTextSet('company','Company');
	$website = isTextSet('web','Web Address');
	$firstname = isTextSet('first','Web Address');
	$lastname = isTextSet('last','Last Name');
	$address = isTextSet('address','Address');
	$city = isTextSet('city','City');
	$state = isTextSet('state','State');
	$zip = isTextSet('zip','Zip code');
	$officenum = isTextSet('officenum','Office Number');	
	$tollfree = isTextSet('tollfree','Toll free Number');
	$fax = isTextSet('fax','Fax');
	$email = isTextSet('email','Email');	
	$airport1 = isTextSet('airport1','1st airport');	
	$airport2 = isTextSet('airport2','2nd airport');
	$airport3 = isTextSet('airport3','3rd airport');
	$airport4 = isTextSet('airport4','4th airport');
	$airport5 = isTextSet('airport5','5th airport');	
	$airport6 = isTextSet('airport6','6th airport');
	$airport7 = isTextSet('airport7','7th airport');
	$airport8 = isTextSet('airport8','8th airport');
	$targetzip1 = isTextSet('targetzip1','Target Zipcode');	
	$targetzip2 = isTextSet('targetzip2','Target Zipcode');
	$targetzip3 = isTextSet('targetzip3','Target Zipcode');
	$targetzip4 = isTextSet('targetzip4','Target Zipcode');	
	$airtrans = 'N';
	if (isServiceSelected('airtrans') == 'selected') $airtrans = 'Y';
	$wedding = isServiceSelectedYN('wedding');
	echom('<br>after wedding<br>');
	$prom = isServiceSelectedYN('prom');
	$bachelor = isServiceSelectedYN('bachelor');
	$anniversaries = isServiceSelectedYN('anniversaries');
	$pt2pt = isServiceSelectedYN('pt2pt');
	$birthday = isServiceSelectedYN('birthday');
	$concert = isServiceSelectedYN('concert');
	$grads = isServiceSelectedYN('grads');
	$sports = isServiceSelectedYN('sports');
	$holiday = isServiceSelectedYN('holiday');
	$nightout = isServiceSelectedYN('nightout');
	$other = isServiceSelectedYN('other');
	
	//fleet selections
	$sedan = isFleetSelectedYN('sedan');
	$stretchlimo = isFleetSelectedYN('stretchlimo');
	$van = isFleetSelectedYN('van');
	$paratrans = isFleetSelectedYN('paratrans');
	$handicap = isFleetSelectedYN('handicap');
	$suv = isFleetSelectedYN('suv');
	$minibus = isFleetSelectedYN('minibus');
	$limo = isFleetSelectedYN('limo');
	$antique = isFleetSelectedYN('antique');
	$rolls = isFleetSelectedYN('rolls');
	$bus620 = isFleetSelectedYN('bus620');
	$bus20up = isFleetSelectedYN('bus20up');
				echo '456';
	//testcodellllllllllllll
	$del = 'delete from companies where id=1;';
	
	$sql = "insert into companies (
	id,
	name,
	website,
	first_name,
	last_name,
	address,
	city,
	state,
	zip,
	office_phone_number,
	toll_free_number,
	fax_number,
	email,
	airport_one,
	airport_two,
	airport_three,
	airport_four,
	airport_five,	
	airport_six,
	airport_seven,
	airport_eight,	
	target_area_one,
	target_area_two,
	target_area_three,
	target_area_four,
	dt_changed,
	airtrans,	
	weddings,
	prom,
	bachelor_party,
	anniversaries,
	point2point,
	birthday_party,
	concert,
	graduation,
	sport_event,
	holiday_lights_tour,
	night_on_the_town,
	other,
	sedan,
	limo,
	strech_limo,
	van,
	paratrans_van,
	handicap_access,
	suv,
	minibus,
	antique_vehicle,
	rolls_royce,
	partybus_620,
	partybus_20plus) values (
	'$id',
	'$company',
	'$website',
	'$firstname',
	'$lastname',
	'$address',
	'$city',
	'$state',
	'$zip',
	'$officenum',
	'$tollfree',
	'$fax',
	'$email',
	'$airport1',
	'$airport2',
	'$airport3',
	'$airport4',
	'$airport5',
	'$airport6',
	'$airport7',
	'$airport8',	
	'$targetzip1',
	'$targetzip2',
	'$targetzip3',
	'$targetzip4',
	'Now()',
	'$airtrans',
	'$wedding',
	'$prom',
	'$bachelor',
	'$anniversaries',
	'$pt2pt',
	'$birthday',
	'$concert',
	'$grads',
	'$sports',
	'$holiday',
	'$nightout',
	'$other',
	'$sedan',
	'$limo',
	'$stretchlimo',
	'$van',
	'$paratrans',
	'$handicap',
	'$suv',
	'$minibus',
	'$antique',
	'$rolls',
	'$bus620',
	'$bus20up')";
	echo '<h2>here</h2>';
	}
	catch (Exception $e) 
	{
		echo 'Caught exception: ',  var_dump($e->getMessage()), "\n";
	}
	runNonQuery($del);
	runNonQuery($sql);

echo '<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>';
//phpinfo();
echo '<br> last error:';
print_r(error_get_last());
}
else
{
	echo '<br> not postback';
}
function isTextSet($control,$label)
{
	$field = '';
	$field = $_POST[$control];
	if ($field)
		if ($field == $label)
			$field = '';
	return $field;
}
function runNonQuery($sql)
{
	try 
	{
			//echo '<h2>test</h2>';
		$con = mysql_connect('cocoagood16.ipowermysql.com','nicedb','nicedbpa55w0rd');
		if (!$con)
		{
			die('Could not connect: ' . mysql_error());
		}
		echom('about to insert');
		mysql_select_db("niceairport", $con);
		echom($sql);
		// Execute query
		$r = mysql_query($sql,$con);
		echom('<h2> query result: ' . ($r ? 'true' : 'false') . '</h2>');
		echom('sqlerr' . mysql_error()); 
		mysql_close($con);

		echom('inserted records');
	}
	catch (Exception $e) 
	{
		echo 'Caught exception: ',  var_dump($e->getMessage()), "\n";
	}		
}
function echom($message)
{
	echo '<br>' . $message . '<br>';
}
function setServices()
{
	$con = mysql_connect('cocoagood16.ipowermysql.com','nicedb','nicedbpa55w0rd');
	if (!$con)
	{
		die('Could not connect: ' . mysql_error());
	}
	
	mysql_select_db("niceairport", $con);
	$result = mysql_query("SELECT * FROM companies");
	if($row = mysql_fetch_array($result))
	{
	  echo $row['FirstName'] . " " . $row['LastName'];
	  echo "<br />";
	}

	mysql_close($con);
}
?>

</body>

</html>
